<?php
/** 
 * EGP Framework
 *
 * LICENSE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 * @version    v1.0.0 Beta @ 2008-10-16
 */

!defined('EGP_LIB_DIR') && die('Access Deny!');

/**
 * 缓存驱动抽像类
 *
 * @package    classes
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */
abstract class EGP_Cache_Abstract
{

    /**
     * 缓存配置相关参数
     *
     * @var array
     */
    protected $_options = array(
       'life_time' => 7200, //缓存生存周期(秒)
    );

    /**
     * 构造函数
     *
     * @param  array  $options
     */
    public function __construct(array $options = array())
    {
        $this->setOptions($options);
    }

    /**
     * 设置缓存存取参数信息
     *
     * @param  array  $options
     */
    public function setOptions(array $options)
    {
        foreach ($options as $key => $value)
            if (isset($this->_options[$key]))
                $this->_options[$key] = $value;
    }

    /**
     * 通过魔术方法设定参数
     *
     * @param  string  $name
     * @param  mixed   $value
     */
    public function __set($name, $value) {
        if (isset($this->_options[$name]))
            $this->_options[$name] = $value;
    }

    /**
     * 保存缓存资料
     *
     * @param  mixed   $value
     * @param  string  $id
     * @return boolean
     */
    abstract public function save($data, $id);

    /**
     * 加载缓存数据
     *
     * @param  string   $id
     * @return mixed|false
     */
    abstract public function load($id);

    /**
     * 移除缓存数据
     *
     * @param  string  $id
     * @return boolean
     */
    abstract public function remove($id);

    /**
     * 移除所有缓存数据
     *
     * @return boolean
     */
    abstract public function clean();

}